const user = require('./services/user.js');
App({
    onLaunch() {
        let that = this
        user.checkLogin((res) => {
            if (res.code == 0) {
                let info = {
                    avatarUrl: res.data.avatarUrl,
                    nickName: res.data.nickName,
                    registerTime: res.data.registerTime
                }
                wx.setStorageSync('login', true)
                wx.setStorageSync('openid', res.data.openid)
                wx.setStorageSync('uid', res.data.uid)
                that.globalData.userInfo = info
            } else {
                wx.setStorageSync('login', false)
                // 登录
                wx.login({
                    success: res => {
                        // 发送 res.code 到后台换取 openId, sessionKey, unionId
                    }
                })
            }
        })


    },
    globalData: {
        userInfo: null
    }
})
